import { start as startAdmin } from "maishu-chitu-admin";
import { stationPath, permissions } from "./website-config";
import path = require("path");
import { Settings, ServerContentData } from "./common";
import { createDatabaseIfNotExists } from "maishu-node-auth";
import { ConnectionConfig } from "mysql";
import { createDataContext } from "./data-context";

export async function start(settings: Settings) {

    await createDatabaseIfNotExists(settings.db, initDatabase);
    await createDataContext(settings.db);

    startAdmin({
        port: settings.port,
        rootDirectory: __dirname,
        station: {
            gateway: `${settings.gateway}`,
            path: stationPath,
            permissions: permissions,
        },
        serverContextData: { db: settings.db } as ServerContentData
    })
}

export async function initDatabase(connConfig: ConnectionConfig) {
}